from twisted.conch import telnet
from twisted.python import log

log.startLogging(file('mud.log','w'), setStdout=False)

import GameState

class MudServer(telnet.StatefulTelnetProtocol):

    def connectionMade(self):
        GameState.add_connection(self.transport)

    def lineReceived(self, line):
        GameState.receive_line(self.transport, line)

    def connectionLost(self, *args, **kwargs):
        GameState.remove_connection(self.transport)

def run():
    from twisted.internet.protocol import Factory
    from twisted.internet import reactor

    factory = Factory()
    factory.protocol = MudServer
    reactor.listenTCP(4000, factory)
    reactor.run()
